package es.xpt.ysf.commons.location.view;

import java.util.ArrayList;
import java.util.List;

import es.xpt.ysf.YSFException;
import es.xpt.ysf.commons.Names;
import es.xpt.ysf.commons.location.LocationSession;
import es.xpt.ysf.commons.location.model.Address;
import es.xpt.ysf.commons.location.model.City;
import es.xpt.ysf.commons.location.model.Country;
import es.xpt.ysf.commons.location.model.Province;
import es.xpt.ysf.view.LocalDelegate;
import es.xpt.ysf.view.model.UserBean;


public class LocationDelegate extends LocalDelegate<LocationSession> {

	public LocationDelegate(UserBean user) {
		super(user);
	}
	
	public List<City> suggestCities(String fragment) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		return ejb.suggestCities(fragment);
	}
	public List<City> suggestMainCitiesForEntity(String fragment, int maxResults, String entity) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		return ejb.suggestMainCitiesForEntity(fragment, maxResults, entity);
	}
	
	public Address getAddress(String addressId ) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		return ejb.getAddress(addressId);
	}
	
	public List<Address> getEntityAddresses(String entity, String entityId ) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		return ejb.getEntityAddresses(entity, entityId);
	}

	public Address getEntityAddressByUse(String entity, String entityId, String use) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		return ejb.getEntityAddressByUse(entity, entityId, use);
	}

	public List<Address> searchAddress(Address address ) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		return ejb.searchAddress(address);
	}
	
	public void addEntityAddress(String entityId, String entity, String addressId, String use) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		ejb.addEntityAddress(entityId, entity, addressId, use);
	}
	
	public void addEntityAddresses(String entityId, String entity, List<String> addresses, String use) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		ejb.addEntityAddresses(entityId, entity, addresses, use);
	}
	
	
	public void removeEntityAddress(String entityId, String entity, String addressId,String use) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		ejb.removeEntityAddress(entityId, entity, addressId, use);
	}
	
	public void updateEntityAddress(Address address) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		ejb.updateAddress(address);
	}
		
	public void insertEntityAddress(Address address, String entityId, String use) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		ejb.insertAddress(address, entityId, use);
	}
	
	public Address insertAddress(Address address) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		return ejb.insertAddress(address);
	}
	
	public void updateAddress(Address address) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		ejb.updateAddress(address);
	}

	public void deleteAddress(String addressId) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		ejb.deleteAddress(addressId);
	}
	
	public ArrayList<String[]> searchDependentEntities(String addressId ) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		return ejb.searchDependentEntities(addressId);
	}
	
	public List<String> searchEntityDependences(String addressId, String entity ) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		return ejb.searchEntityDependences(addressId,entity);
	}
	
	
	/************************* PAISES ***********************************************/
	public List<Country> findAllCountry() throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		return ejb.findAllCountry();

	}

	public List<Country> getCountry(String id) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		return ejb.getCountry(id);
	}

	public void updateCountryi18n(List<Country> countryi18n) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		ejb.updateCountryi18n(countryi18n);

	}

	public void deleteCountry(String id, String locale) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		ejb.deleteCountry(id, locale);

	}
	
	public void createCountry(Country country) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		ejb.createCountry(country);

	}
	
	public List<Country> suggestCountries(String fragment) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		return ejb.suggestCountries(fragment);
	}
	
/************************* PROVINCIAS **********************************************/
	public List<Province> getProvinceByCountry(String country) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		return ejb.getProvinceByCountry(country);

	}
	
	public List<Province> getProvince(String id) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		return ejb.getProvince(id);

	}
	

	public void createProvince(Province province) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		ejb.createProvince(province);

	}

	public void updateProvinceI18n(List<Province> provinceI18n) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		ejb.updateProvinceI18n(provinceI18n);
	}

	
	public void deleteProvince(Province province, String locale) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		ejb.deleteProvince(province, locale);

	}
	
	public List<Province> suggestProvinces(String fragment) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		return ejb.suggestProvinces(fragment);
	}
	
/************************* CIUDADES ***********************************************/
	public List<City> getCityByProvince(String province) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		return ejb.getCityByProvince(province);

	}
	
	public List<City> getCity(String id) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		return ejb.getCity(id);

	}
	
	public void createCity(City settlement) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		ejb.createCity(settlement);

	}

	public void deleteCity(String id, String locale) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		ejb.deleteCity(id, locale);

	}
	
	public void updateCityI18n(List<City> cityI18n) throws YSFException {
		LocationSession ejb = connect(Names.LOCATION);
		ejb.updateCityI18n(cityI18n);
	}
	
	public List<String> deleteBatchAddress(List<String> listCodeAddress) throws YSFException{
		LocationSession ejb = connect(Names.LOCATION);
		return ejb.deleteBatchAddress(listCodeAddress);
	}
	
	public List<City> searchCity(City city) throws YSFException{
		LocationSession ejb = connect(Names.LOCATION);
		return ejb.searchCity(city);
	}

}
